﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WebBags.Controllers
{
    public class ProductController : Controller
    {
        private DBWebBagsDataContext db = new DBWebBagsDataContext();

        public ActionResult Index()
        {
            List<Product> lstNew = db.Products.OrderByDescending(x => x.CreationDate).Take(5).ToList();
            ViewData["LstNew"] = lstNew;
            string strLang = System.Globalization.CultureInfo.CurrentCulture.DisplayName.Substring(0, 1).ToLower();
            Category c = db.Categories.First();
            List<Product> lst = db.Products.Where(p => p.CategoryId == c.ID).Take(5).ToList();
            ViewData["Lst"] = lst;            
            ViewData["CategoryName"] = (strLang == "v") ? c.Name_vn : c.Name_en;
            return View();
        }

        public ActionResult ListProduct(long id)
        {
            string strLang = System.Globalization.CultureInfo.CurrentCulture.DisplayName.Substring(0, 1).ToLower();
            Category c = db.Categories.Where(x => x.ID == id).First();
            string strName = (strLang == "v") ? c.Name_vn : c.Name_en;
            List<Product> lst = db.Products.Where(x => x.CategoryId == id).ToList();
            ViewData["name"] = strName.ToUpper();
            ViewData["lst"] = lst;
            return View();
        }

        public ActionResult Detail(long id)
        {
            Product p = db.Products.Where(x => x.ID == id).First();
            List<ImageProduct> lst = db.ImageProducts.Where(x => x.ProductId == id).ToList();
            ViewData["lstImage"] = lst;
            return View(p);
        }
    }
}
